<template>
	<view class="pages-row">
		<view class="card-line" v-if="list.length !== 0">
			<view v-for="(it, ix) in list" :key="ix" @click="goDetails(it)" hover-class="hover_class">
				<view>
					<image :src="it.goods_info.image"></image>
					<view>
						<view>{{ it.goods_info.name }}</view>
						<view>{{ it.goods_info.describe }}</view>
						<view>
							<text>￥</text>
							<view>{{ it.goods_info.shop_price }}</view>
						</view>
					</view>
				</view>
				<image @click.stop="collection(it)" src="../../../static/image/version/shou.png"></image>
			</view>
		</view>
		<view v-else class="emptyds">
			<empty title="暂无收藏信息"/>
		</view>
	</view>
</template>

<script>
import {
	collectList,
	userCollect
} from '@/utils/api/home.js'

export default {
	data() {
		return {
			list: []
		}
	},
	created() {
		this.getList()
	},
	methods: {
		// 收藏
		collection(it) {
			uni.showLoading({
				title: '操作中'
			})
			userCollect({productId: it.goods_info.id}).then((res) => {
				setTimeout(() => {
					uni.showToast({
						title: '取消收藏成功',
						icon: 'none'
					})
					this.getList()
				}, 300)
			})
		},
		getList() {
			uni.showLoading({
				title: '加载中'
			})
			collectList().then((res) => {
				this.list = res.data || []
			}).finally(() => {
				uni.hideLoading()
			})
		},
		goDetails(item) {
			uni.navigateTo({
				url: '/managePackage/pages/shopDetail/index?id=' + item.goods_info.id
			})
		}
	}
}
</script>

<style scoped lang="scss">
.emptyds {
	height: 90vh;
	display: flex;
	align-items: center;
	justify-content: center;
}
.pages-row {
	width: 100%;
	min-height: 100vh;
	box-sizing: border-box;
	padding: 30upx 20upx;
	background-color: #F6F6F6;
	>.card-line {
		background-color: #fff;
		border-radius: 20upx;
		box-sizing: border-box;
		padding: 24upx;
		>view:not(:last-child) {
			margin-bottom: 39upx;
		}
		>view {
			display: flex;
			align-items: center;
			justify-content: space-between;
			>image {
				width: 42upx;
				height: 37upx;
			}
			>view {
				display: flex;
				align-items: center;
				>image {
					width: 160upx;
					height: 160upx;
					border-radius: 15upx;
					margin-right: 30upx;
				}
				>view {
					>view:nth-of-type(1) {
						font-size: 26upx;
						color: #000000;
						font-weight: 500;
						margin-bottom: 15upx;
						 white-space: nowrap;
						  overflow: hidden;
						  text-overflow: ellipsis;
						  max-width: 380upx;
					}
					>view:nth-of-type(2) {
						font-size: 26upx;
						color: #969696;
						margin-bottom: 38upx;
					}
					>view:nth-of-type(3) {
						display: flex;
						align-items: flex-end;
						color: #E00B0B;
						font-weight: bold;
						font-size: 30upx;
						>text {
							color: #E00B0B;
							font-size: 18upx;
							margin-bottom: 2upx;
						}
					}
				}
			}
		}
	}
}
</style>